Ext.define('Admin.view.page.operation.setting.Setting', {
    extend: 'Ext.panel.Panel',
    requires: [
        'Admin.store.operation.setting.SettingStore',
        'Admin.view.page.operation.setting.SettingController',
        'Admin.view.page.operation.setting.SettingModel',
        'Admin.model.operation.setting.Setting',
        // 'Ext.layout.container.HBox',
        // 'Ext.data.*',
        // 'Ext.grid.*',
        // 'Ext.util.*',
        // 'Ext.toolbar.Paging',
        // 'Ext.ux.PreviewPlugin',
    ],
    controller: 'group-menu',
    viewModel: 'group-menu',
    // id : 'group-menu-view',
    xtype: 'task-operation-setting-view',
    title: '标志操作配置',
    frame: true,
    layout: {
        type: 'hbox',
        pack: 'start',
        align: 'stretch'
    },
    // rendered : true,
    // height: Ext.Element.getViewportHeight(),
    // bodyPadding: 10,
    // padding : '0 10 0 0',
    defaults: {
        frame: true,
        bodyPadding: 10
    },
    reference : 'groupMenuViewReference',
    initComponent: function(){
        // let menuStore = Ext.create('Admin.store.operation.setting.SettingStore',{
        //     proxy: {
        //         type: 'ajax',
        //         url: '/ye/group/query',
        //         reader: {
        //             type: 'json',
        //             // type: 'array',
        //             rootProperty: 'data',
        //             totalProperty: 'count'
        //         }, 
        //         // Store设置请求的方法 GET POST 
        //         actionMethods : {  
        //             read : 'GET' 
        //         },  
        //         writer : {    			
        //             type : 'json'
        //         }	
        //     },
        // });
        let projectStore = Ext.create('Admin.store.group.menu.ChildGroupStore',{
                proxy: {
                    type: 'ajax',
                    url: '/ye/group/queryChildGroup',
                    reader: {
                        type: 'json',
                        // type: 'array',
                        rootProperty: 'data',
                        totalProperty: 'count'
                    }, 
                    // Store设置请求的方法 GET POST 
                    actionMethods : {  
                        read : 'GET' 
                    },  
                    writer : {    			
                        type : 'json'
                    }	
                },
        });

        let menuGridPanel = Ext.create('Ext.grid.Panel', 
        {
            
            title: '菜单',
            reference: 'menuGridPanel',
            // store : menuStore,
            bind : {
                store : '{menuStore}',
            },
            bbar: Ext.create('Ext.PagingToolbar', {
                // store: store,
                // pageSize: 20,
                bind : {
                    store : '{menuStore}',
                },
                displayInfo: true,
                displayMsg: '共{2}条,第 {0}到 {1}条',
                emptyMsg: "无记录",
                listeners: {
                    beforechange: 'menuGridPanelPagingToolbarBeforechange',
                }
            }),
            plugins: {
                ptype: 'cellediting',
                clicksToEdit: 2
            },
            selModel: {
                // type: 'cellmodel',
                selType: 'rowmodel',
            },
            // height: 200,
            // width: 400,
            flex: 3,
            tbar: [{
                    xtype: 'textfield',
                    fieldLabel: '关键字',
                    labelWidth: 50,
                    // bind : {
                    //     value : '{menuGridKeyword}'
                    // }
                    bind: '{menuGridKeyword}'
                },'-',{ 
                    xtype: 'button',
                    text: '查询' ,
                    handler: 'queryMenuButton'
                },'->',{ 
                    xtype: 'button',
                    text: '添加' ,
                    handler: 'addMenuButton'
                },{ 
                    xtype: 'button',
                    text: '保存' ,
                    handler: 'saveMenuButton'
                },{ 
                    xtype: 'button',
                    text: '删除' ,
                    handler: 'deleteMenuButton'
                },
            ],
            columns : [{
                    xtype: 'rownumberer'
                }, { 
                    header: '菜单名称',
                    sortable: true,
                    dataIndex: 'name',
                    editor: {
                        xtype: 'textfield',
                        allowBlank: false
                    },
                    flex: 2
                },{
                    header: '排序',
                    sortable: true,
                    dataIndex: 'sort',
                    editor: {
                        xtype: 'numberfield',
                        allowBlank: false,
                        minValue: 0,
                        // maxValue: 100000
                    },
                    flex: 1
                },{
                    header: '组备注',
                    sortable: true,
                    dataIndex: 'remarks',
                    editor: {
                        xtype: 'textfield',
                        allowBlank: false
                    },
                    flex: 1
                }
            ],
            listeners: {
                //渲染完成后,加载数据
                afterrender: 'yeMenuGridAfterrender',
                //单击加载子项数据
                rowclick: 'yeMenuGridRowclick',
            }
        });
        let projectGridPanel = Ext.create('Ext.grid.Panel', 
        {
            
            title: '关联项目',
            reference: 'projectGridPanel',
            store : projectStore,
            bbar: Ext.create('Ext.PagingToolbar', {
                store: projectStore,
                // pageSize: 20,
                // bind : {
                //     store : '{menuStore}',
                // },
                displayInfo: true,
                displayMsg: '共{2}条,第 {0}到 {1}条',
                emptyMsg: "无记录",
                listeners: {
                    beforechange: 'projectGridPanelPagingToolbarBeforechange',
                }
            }),
            plugins: {
                ptype: 'cellediting',
                clicksToEdit: 2
            },
            selModel: {
                type: 'rowmodel'
            },
            // height: 200,
            // width: 400,
            flex: 1,
            tbar: ['->',{ 
                    xtype: 'button',
                    text: '添加' ,
                    handler: 'addMenuProjectButton'
                },{ 
                    xtype: 'button',
                    text: '保存' ,
                    handler: 'saveMenuProjectButton'
                },{ 
                    xtype: 'button',
                    text: '删除' ,
                    handler: 'deleteMenuProjectButton'
                },
            ],
            columns : [
                { 
                    header: '菜单名称',
                    sortable: true,
                    dataIndex: 'name',
                    flex: 2 ,
                    editor: new Ext.form.field.ComboBox({
                        typeAhead: true,
                        // triggerAction: 'all',
                        displayField : 'name',
                        valueField : 'id',
                        pageSize : 20,
                        reference: 'projectGridPanelNameComboBox',
                        queryMode: 'remote',
                        // queryMode: 'local',
                        queryDelay : 1000,
                        queryParam : 'keyword',
                        minChars : 1,
                        // hideTrigger : false,
                        // triggerAction: 'all', // 点击时弹出下拉列表
                        // loader: {
                        //     autoLoad: false
                        // },
                        // hiddenName : 'useWay',
                        /* dockedItems: [{
                            xtype: 'pagingtoolbar',
                            // store: store,
                            bind :{
                                store : '{menuComboStore}',
                            },
                            dock: 'bottom',
                            displayInfo: true,
                            displayMsg: 'Displaying items {0} - {1} of {2}',
                            emptyMsg: 'No items to display'
                        }], */
                        // store : Ext.create('Admin.store.operation.setting.SettingStore',{
                        //     autoLoad:false,
                        //     proxy: {
                        //         type: 'ajax',
                        //         // baseParams :{
                        //         //     groupType : 2,
                        //         // },
                        //         url: '/ye/group/query',
                        //         reader: {
                        //             type: 'json',
                        //             rootProperty: 'data',
                        //             totalProperty: 'count'
                        //         }, 
                        //         // Store设置请求的方法 GET POST 
                        //         actionMethods : {  
                        //             read : 'GET' 
                        //         },  
                        //         writer : {    			
                        //             type : 'json'
                        //         }	
                        //     },
                        // }),
                        bind :{
                            store : '{menuComboStore}',
                        },
                        listeners: {
                            //组件活动时加载数据
                            beforequery: 'yeProjectNameEditorBeforequery',
                            //选择后
                            select: 'yeProjectNameEditorSelect',
                            afterrender: 'yeProjectNameEditorAfterrender',
                        }
                    }),
                    //组件活动时加载数据
                    renderer: 'yeProjectNameRenderer',
                }, { 
                    header: '排序',
                    sortable: true,
                    dataIndex: 'sort',
                    flex: 1 ,
                    editor: {
                        xtype: 'numberfield',
                        allowBlank: false,
                        minValue: 0,
                        // maxValue: 100000
                    },
                }
            ],
            listeners: {
                //渲染完成后,加载数据
                afterrender: 'yeProjectGridAfterrender',
            }
        });
        Ext.apply(this,{
            items: [
                menuGridPanel,
                projectGridPanel
            ]
        }
        )
        this.callParent();
    },
    listeners: {
        //渲染完成后,自定义宽高
        afterrender: 'yeAfterrender',
    }
});
